<template>
  <el-dialog
    title="新增流程"
    :visible.sync="dialogVisible"
    width="30%"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form :model="formData" :rules="rules" label-width="100px" ref="form">
      <el-form-item label="服务名称" prop="fwmc">
        <el-input v-model="formData.fwmc" maxlength="50" />
      </el-form-item>
      <el-form-item label="服务版本" prop="fwbb">
        <el-input v-model="formData.fwbb" maxlength="50" />
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="addBpfw">确定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import bpfwglService from "@/api/bpfwgl";
export default {
  data() {
    return {
      // 是否显示弹窗
      dialogVisible: false,
      // 新增流程表单数据
      formData: {
        fwbb: "",
        fwmc: ""
      },
      // 表单校验规则
      rules: {
        fwmc: [
          { required: true, message: "请输入服务名称", trigger: "change" }
        ],
        fwbb: [{ required: true, message: "请输入服务版本", trigger: "change" }]
      }
    };
  },
  methods: {
    // 打开弹窗
    openDialog() {
      this.$refs.form?.resetFields();
      this.dialogVisible = true;
    },
    // 新增编排服务
    addBpfw() {
      this.$refs.form?.validate(valid => {
        if (valid) {
          bpfwglService
            .addBpfw(this.formData)
            .then(() => {
              this.$emit("updateTable");
              this.$message({ type: "success", message: "新增成功!" });
              this.dialogVisible = false;
            })
            .catch(err => {
              !err.isError &&
                this.$message({ type: "warning", message: err.message });
            });
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped></style>
